/***************************/
/*Bat dau chuc nang hien thi danh sach*/
function xemchitiet()
{
	var ChuoiLoi = kiemtra();

    if(ChuoiLoi!="")
    {
        var Chuoi = "Co loi xay ra:\n"
        Chuoi += ChuoiLoi;
        alert(Chuoi);
    }
    else
    {
		var MaSo = document.getElementById('txtMa').value;
		var url="xemchitiet.php?MaSo=" + MaSo;
		window.location = url;


		
		
	}
}


function XoaChiTiet(id) {
	//var url = "temp.php?idXoa=" + id;
  	//document.location.href = url
	

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "xlXoa.php?idXoa=" + id;

	xmlhttp.onreadystatechange=xoact_stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
	 
}
function xoact_stateChanged()
{
		
	if (xmlhttp.readyState==4)
	{
		
		
		if (xmlhttp.status == 200)
		{
		
			//var xmlDoc=xmlhttp.responseXML.documentElement;		
			//var xmlDoc=xmlhttp.responseXML;
			
			//var response_stat = xmlDoc.getElementsByTagName("deleted")[0].childNodes[0].nodeValue;			
			//var response_stat=xmlDoc.getElementsByTagName("deleted")[0].firstChild.data;			
			
			var response_stat=xmlhttp.responseText;
			
            if(response_stat == 1)
			{
				alert('Deleted row successfully.');
				var url="xemchitiet.php";
				window.location = url;
			}
			else
			{
				alert('Failed to delete');
			}
		} 
	}
}

/*Ket thuc chuc nang hien thi danh sach**/
/***************************/	


function capnhatchitiet(ma)
{
	var MaSo = document.getElementById(ma + " ma").value;	
	var Ten = document.getElementById(ma + " ten").value;
	var DiaChi = document.getElementById(ma + " diachi").value;
	var DienThoai = document.getElementById(ma + " dienthoai").value;
	var NgaySinh = document.getElementById(ma + " ngaysinh").value;
	
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="xlcapnhat.php?MaSo=" + MaSo + "&Ten=" + Ten + "&DiaChi=" + DiaChi + "&DienThoai=" + DienThoai  + "&NgaySinh=" + NgaySinh;
	xmlhttp.onreadystatechange=capnhatchitiet_stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
	
function capnhatchitiet_stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		var response_stat=xmlhttp.responseText;
			
        if(response_stat == 1)
		{
			alert('Cap nhat thanh cong.');
		}
		else
		{
			alert('Cap nhat that bai');
		}
	}
}